package com.ktjy;

import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SpringBootTest(classes = ZjgdcrmApplication.class)
public class ActivitiTest2 {
    @Autowired
    RepositoryService repositoryService;
    @Autowired
    RuntimeService runtimeService;
    @Autowired
    TaskService taskService;
    @Autowired
    HistoryService historyService;

    @Test
    public void test(){
        //流程图部署
        Deployment deployment = repositoryService.createDeployment()
                .name("活动申请2.0")
                .addClasspathResource("bpmn/Activity2.bpmn20.xml")
                .deploy();
        System.out.println("部署成功，流程部署ID："+ deployment.getId());
    }

    @Test
    public void test2(){
        //启动流程
        //流程定义id
        String processDefinitionId="Activity2:1:a5fea772-821c-11f0-adc5-fc5cee562398";
        //流程实例
        ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinitionId);
        System.out.println("启动成功");
    }

    @Test
    public void test3(){
        //查询待办任务
        List<Task> list = taskService.createTaskQuery()
                .taskAssignee("张娜娜").list();

        for (Task task : list) {
            System.out.println("任务ID：" + task.getId());
            System.out.println("流程实例ID：" + task.getProcessInstanceId());
            System.out.println("流程执行ID：" + task.getExecutionId());
            System.out.println("流程定义ID：" + task.getProcessDefinitionId());
            System.out.println("任务名称：" + task.getName());
            System.out.println("任务办理人：" + task.getAssignee());
        }
    }

    @Test
    public void test4(){
        String taskId="d74565ce-821c-11f0-8619-fc5cee562398";
        Map<String,Object> param=new HashMap<>();
        param.put("outcome","通过");
        taskService.complete(taskId);
        System.out.println("完成任务成功");
    }
}
